home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / misc / rxsocket / udp.rexx < prev   
OS/2 REXX Batch file  |  1998-05-24  |  1KB  |  84 lines

  1. /*
  2.     udp test translated into rexx
  3.     from Amiga Magazine 93 udp.c test by Rudi Chiarito
  4.  
  5.     usage: udp host port localPort
  6.  
  7.     i.e. :
  8.         shell1 udp localhost 4000 4001
  9.         shell2 udp localhost 4001 4000
  10.  
  11.     to stop push <ctrl-c> in the shells
  12.  
  13. */
  14.  
  15. parse arg host remotePort localPort .
  16.  
  17. remote.ADDRFAMILY = "INET"
  18. remote.ADDRPORT   = remotePort
  19.  
  20. addr = inetaddr(host)
  21. if addr == -1 then do
  22.     if ~gethostbyname("SERVER",host) then do
  23.         say "Host" host "non trovato."
  24.         exit
  25.     end
  26.     remote.ADDRFAMILY = server.HOSTADDRTYPE
  27.     remote.ADDRADDR   = server.HOSTADDRLIST.0
  28. end
  29. else remote.ADDRADDR = addr
  30.  
  31. sock = socket("INET","DGRAM","IP")
  32. if sock < 0 then do
  33.     say "Non posso aprire il socket:" Errno()
  34.     exit
  35. end
  36.  
  37. LOCAL.ADDRFAMILY = "INET"
  38. LOCAL.ADDRADDR     = 0
  39. LOCAL.ADDRPORT   = localPort
  40. res = bind(sock,"LOCAL")
  41. if res < 0 then do
  42.     say "Non posso allocare la porta:" Errno()
  43.     exit
  44. end
  45.  
  46. say "Host:" host
  47.  
  48. call IOCTLSOCKET(sock,"FIONBIO",1)
  49.  
  50. data = "Ciao"
  51. down = 0
  52. do while 1
  53.  
  54.     n = sendto(sock,data,0,"REMOTE")
  55.     if n < 0 then do
  56.         say "Errore di sendto():" Errno()
  57.         exit
  58.     end
  59.  
  60.     call Delay(10)
  61.  
  62.     if down then call writech("STDOUT",".")
  63.  
  64.     n = recvfrom(sock,"BUFF",10,0,"REMOTE")
  65.     if n==-1 then do
  66.         err = Errno()
  67.         if err==35 then do
  68.             if ~down then do
  69.                 call writech("STDOUT","Non ricevo più dati .")
  70.                 down=1
  71.             end
  72.         end
  73.         else do
  74.             say "Errore di recvfrom():" err
  75.             exit
  76.         end
  77.     end
  78.     else do
  79.         say "Byte letti:" n
  80.         down=0
  81.     end
  82.  
  83. end
  84.